﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ImageButtonLogin_Click(object sender, ImageClickEventArgs e)
    {
        string userId = TextBoxUserName.Text.ToLower().Trim();
        string userPwd = TextBoxPassword.Text.ToLower().Trim();
        //判断空值
        if (!String.IsNullOrEmpty(userId)&&!String.IsNullOrEmpty(userPwd))
        {
            //判断登陆
            if (LoginBLL.UserLogin(userId,userPwd))
            {
                //获取用户数据
                PBOffice.DAL.User user = LoginBLL.SelectUserManageByUserIdAndUserPwd(userId, userPwd);
                if (user!=null)
                {
                    DateTime time = DateTime.Now;
                    //获取IP地址
                    string loginIP = Request.ServerVariables["REMOTE_ADDR"].ToString();
                    Session["loginTime"] = time;
                    Session["userManage"] = user;
                    LoginBLL.AddLoginLogs(user, time, loginIP);
                    //Response.Redirect("~/Default.aspx");
                    Response.Redirect("~/NewsManageModule/newsManage.aspx");
                }
                else
                {
                    Response.Write("<script>alert('未知原因，登陆失败');window.location.href='login.aspx'</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('用户名或密码错误');window.location.href='login.aspx'</script>");
                TextBoxPassword.Text = "";
                TextBoxPassword.Focus();
            }
        }
    }
}